/* 右键菜单 */
const { Menu, ipcMain, BrowserWindow } = require("electron");

// 页面右键菜单
const contextMenuTemplate = [
    { label: "剪切", role: 'cut' },
    { label: "复制", role: 'copy' },
    { label: "粘贴", role: 'paste' },
    { label: "粘贴并匹配格式", role: 'pasteAndMatchStyle' },
    { label: "删除", role: 'delete' },
    { label: "全选", role: 'selectAll' },
    { type: 'separator' },
    // 分隔线 
    { label: '其他功能', click: () => { console.log('click') } }
];
const contextMenu = Menu.buildFromTemplate(contextMenuTemplate);

// 监听右键菜单消息
ipcMain.on("showContextMenu", () => {
    contextMenu.popup({ window: BrowserWindow.getFocusedWindow() });
});